package com.app.demo.service;

import com.app.demo.bean.YourBean;
import com.app.demo.dao.YourBeanDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class YourBeanService {
    @Autowired
    YourBeanDao yourBeanDao;

    public YourBean login(String name,String password){
        List<YourBean> yourBeanList = yourBeanDao.findByNameAndPassword(name,password);
        if(yourBeanList!=null && yourBeanList.size()>0){
            return yourBeanList.get(0);
        }else{
            return null;
        }
    }
    public YourBean update(YourBean yourBean){
        YourBean savedYourBean = yourBeanDao.save(yourBean);
        return savedYourBean;
    }
    public YourBean regist(YourBean yourBean){
        YourBean savedYourBean = yourBeanDao.save(yourBean);
        return savedYourBean;
    }
    public void deleteById(Integer id){
        yourBeanDao.deleteById(id);
    }
    public YourBean findById(Integer id){
        Optional<YourBean> optional = yourBeanDao.findById(id);
        return optional.orElse(null);
    }
    public YourBean addNew(YourBean yourBean){
        YourBean savedYourBean = yourBeanDao.save(yourBean);
        return savedYourBean;
    }
    public List<YourBean> findAll(){
        List<YourBean> yourBeanList = yourBeanDao.findAll();
        return yourBeanList;
    }

}

